//
//  Person.m
//  HomeWork 05 排序、数组字典的处理
//
//  Created by dllo on 16/7/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Person.h"

@implementation Person
- (instancetype)initWithName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender{
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _gender = gender;
    }
    return self;
}
+ (instancetype)personWithName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender{
    return [[Person alloc]initWithName:name age:age gender:gender];
}
- (NSString *)description {
    return [NSString stringWithFormat:@"%@ %ld %@",self.name,self.age,self.gender];
}
- (NSComparisonResult)asSortedByName:(Person *)another {
    return [self.name compare:another.name];
}
- (NSComparisonResult)asSortedByGender:(Person *)another {
    return [self.gender compare:another.gender];
}
- (NSComparisonResult)asSortedByAge:(Person *)another {
    if (self.age > another.age) {
        return NSOrderedDescending;
    }else if (self.age < another.age) {
        return NSOrderedAscending;
    }else {
        return NSOrderedSame;
    }
}
@end
